home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM 1995 Fall / PD-ROM F95.toast / Telecom / Internet / Internet A-M / MacHTTP 1.2.3 ƒ / AppleEvent Info / search.exe < prev   
Encoding:
Text File  |  1994-01-10  |  2.0 KB  |  46 lines  |  [TEXT/ttxt]

  1. --WARNING!!! This script must be saved as an executable application before using
  2. -- it with MacHTTP. Use Save As an Application with the Keep Open and 
  3. -- Never Show Startup Screen boxes checked!!!!
  4. --
  5. -- This script demonstrates accessing searchable files from MacHTTP.
  6. -- (What it really shows is how to pass AppleEvent arguments to AppleScripts.)
  7. -- http_search_args is defined from an AppleEvent passed from the server
  8. --  to the script and contains the client-supplied search arguments. If the arguments
  9. --  are empty, the script returns HTML asking the WWW client to prompt for them. 
  10. --  If arguments were passed, then the script behaves accordingly.
  11. --  Note: the <ISINDEX> HTML tag is what tells the client the document is searchable
  12. --    and arguments should be collected and passed. 
  13.  
  14. set byebye to false --This flag is used to cause the script to (eventually) quit
  15.  
  16. -- The following is a handler for a specific AppleEvent that is sent
  17. -- by MacHTTP to applications. The event suite is 'WWWΩ' and the event itself
  18. -- is the "search" event, 'srch'. The direct parameter contains the 
  19. -- search arguments passed from the WWW client to MacHTTP.
  20. -- Note: The "«" character is generated by typing option-\ and "»" is obtained by typing option-|.
  21. --
  22. -- This very simple "search" looks for the word "hello" and responds accordingly
  23.  
  24. on «event WWWΩsrch» http_search_args
  25.     global byebye
  26.     if http_search_args = "" then --no args passed, tell the client to prompt for them
  27.         set byebye to true
  28.         return "<ISINDEX><h2>Please enter the keyword to search for.</h2>"
  29.     else if http_search_args = "hello" then --the arg matches
  30.         set byebye to true
  31.         return "<h2>Hello, how are you?</h2>"
  32.     else --the arg doesn't match
  33.         set byebye to true
  34.         return "<h2>Sorry, I don't understand '" & ¬
  35.             http_search_args & "'. Try 'hello' instead.</h2>"
  36.     end if
  37.     quit
  38. end «event WWWΩsrch»
  39.  
  40. --The idle handler will cause the script to (eventually) quit. I'd
  41. --love to hear if there's a better way to do this.
  42.  
  43. on idle
  44.     global byebye
  45.     if byebye then quit
  46. end idle